import { requestClient } from '#/api/request';

export namespace ToolApi {
  export type Params = object;
  export interface GetToolReq {
    pageNum: number;
    pageSize: number;
  }
  export interface Row {
    searchValue: null;
    createBy: string;
    createTime: Date;
    updateBy: string;
    updateTime: null;
    remark: string;
    params: Params;
    toolId: number;
    toolCode: null | string;
    toolName: string;
    brand: string;
    spec: string;
    toolTypeId: number;
    toolTypeCode: string;
    toolTypeName: string;
    codeFlag: string;
    quantity: number;
    quantityAvail: number;
    maintenType: string;
    nextMaintenPeriod: null | number;
    nextMaintenDate: Date | null;
    status: string;
    attr1: boolean | null | string;
    attr2: null;
    attr3: number;
    attr4: number;
  }
  export interface GetToolListResp {
    total: number;
    rows: Row[];
    code: number;
    msg: string;
  }
  export interface createToolReq {
    toolId: null;
    toolCode: string;
    toolName: string;
    brand: string;
    spec: string;
    toolTypeId: number;
    toolTypeCode: null;
    toolTypeName: null;
    quantity: number;
    quantityAvail: number;
    maintenType: string;
    nextMaintenPeriod: null;
    nextMaintenDate: Date;
    status: string;
    createBy: null;
    createTime: null;
    updateBy: null;
    updateTime: null;
    codeFlag: string;
    remark: string;
  }
}

// 获取类型列表
export const getToolList = (params: ToolApi.GetToolReq) =>
  requestClient.get<ToolApi.GetToolListResp>('/mes/tm/tool/list', {
    params,
  });

// 修改仓库设置
export const updateTool = (data: ToolApi.Row) =>
  requestClient.put<ToolApi.GetToolListResp>('/mes/tm/tool', data);

// 增加仓库设置
export const addTool = (data: ToolApi.Row) =>
  requestClient.post<ToolApi.GetToolListResp>('/mes/tm/tool', data);

// 删除仓库设置
export const deleteTool = (id: string) =>
  requestClient.delete<ToolApi.GetToolListResp>(`/mes/tm/tool/${id}`);

export const createTool = (params: ToolApi.createToolReq) =>
  requestClient.post<ToolApi.GetToolListResp>('/mes/tm/tool', params);
